#include "modules/buffer_mgr.h"

void create_table_test(string &tblname)
{
	try
	{
		BufferManager bm(0); //no blocks for create test
		bm.create_table(tblname);
	}
	catch(Exception e)
	{
		printf("\nFailed with error : %d", e.errno);
	}
}

void drop_table_test(string &tblname)
{
	BufferManager bm(0); //no blocks for now. May add some blocks to check if the buffers are flushed
	bm.drop_table(tblname);
}

void create_block_test(string &tblname, int num_blocks)
{
	BufferManager bm(0); //no blocks for now. May add some blocks to check if the buffers are flushed
	for(int i=0; i<num_blocks;i++)
	{
		int block_num = bm.create_block(tblname);
		printf("\nCreated block : %d", block_num);
	}
}

int main(int argc, char **argv)
{
	if(argc < 2)
	{
		printf("bufmgr_test [test_name] [test_params]");
		return -1;
	}
	
	string test_name(argv[1]);
	
	if(test_name == "create_table")
	{
		string tblname(argv[2]);
		create_table_test(tblname);
	}
	else if(test_name == "drop_table")
	{
		string tblname(argv[2]);
		drop_table_test(tblname);
	}
	else if(test_name == "create_block")
	{
		int num_blocks;
		string tblname(argv[2]);
		sscanf(argv[3], "%d", &num_blocks);
		create_block_test(tblname, num_blocks);
	}
	
	return 0;
}
